#include <bits/stdc++.h>
using namespace std;
int p1[105][105];
int main(void)
{
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            scanf("%d", &p1[i][j]);
        }
    }
    for (int i = 1; i <= n; i++)
    {
        for (int j = m - 1; j >= 1; j--)
        {
            if (p1[i][j] != 0)
            {
                p1[i][j] = p1[i][j + 1] + p1[i][j];
            }
        }
    }
    int mx = 0;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            int tmp = p1[i][j];
            for (int l = i; l <= n; l++)
            {
                if (p1[l][j] >= p1[i][j])
                    tmp--;
                else
                    break;
            }
            if (!tmp)
            {
                mx = max(p1[i][j], mx);
            }
        }
    }
    for (int i = n; i >=1; i--)
    {
        for (int j = 1; j <= m; j++)
        {
            int tmp = p1[i][j];
            for (int l = i; l >=1; l--)
            {
                if (p1[l][j] >= p1[i][j] && p1[i][j] !=0)
                    tmp--;
                else
                    break;
            }
            if (tmp<=0 && p1[i][j]!=0)
            {
                mx = max(p1[i][j], mx);
            }
        }
    }
    cout << mx << endl;
    return 0;
}